package med.movyzer.gui;

import java.awt.Color;

import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CombinedDomainXYPlot;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.chart.renderer.xy.XYAreaRenderer;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;

@SuppressWarnings("serial")
public class MovyzerPlot extends CombinedDomainXYPlot{

	private XYItemRenderer mRenderer;
	private XYItemRenderer plmRenderer;
	private XYPlot gt3xPlotLeft=new XYPlot();
	private XYPlot gt3xPlotRight=new XYPlot();
	private XYPlot psgPlot=new XYPlot();
	private NumberAxis movIntensAxis=new NumberAxis("Movement Intensity");
	private NumberAxis isMovAxis=new NumberAxis("Is Movement");
	
	
	public MovyzerPlot(){
		this.setDomainAxis(new DateAxis());
		this.add(gt3xPlotLeft);
		this.add(gt3xPlotRight);
		this.add(psgPlot);
		init();
	}
	
	public void init(){
		mRenderer = new XYAreaRenderer();
		mRenderer.setSeriesPaint(0, Color.RED.brighter());
		((XYAreaRenderer)mRenderer).setOutline(true);
		((XYAreaRenderer)mRenderer).setBaseOutlinePaint(Color.RED);
		
		plmRenderer = new StandardXYItemRenderer();
		plmRenderer.setSeriesPaint(0, Color.BLUE);
		
		movIntensAxis.setAutoRange(true);
		isMovAxis.setAutoRange(true);
	}
	
	public void setGT3XDataLeft(TimeSeries mSeries,TimeSeries plmSeries,TimeSeries lmSeries) {
		gt3xPlotLeft.setDataset(0, new TimeSeriesCollection(mSeries));
		gt3xPlotLeft.setDataset(1, new TimeSeriesCollection(plmSeries));
		gt3xPlotLeft.setDataset(2, new TimeSeriesCollection(lmSeries));
		gt3xPlotLeft.setRenderer(0, mRenderer);
		gt3xPlotLeft.setRenderer(1, plmRenderer);
		gt3xPlotLeft.setRangeAxis(0, new NumberAxis("GT3X Movement Intensity"));
		gt3xPlotLeft.setRangeAxis(1, new NumberAxis("is PL-Movement"));
		gt3xPlotLeft.mapDatasetToRangeAxis(0, 0);
		gt3xPlotLeft.mapDatasetToRangeAxis(1, 1);
		gt3xPlotLeft.setForegroundAlpha(0.6f);
	}
	public void setGT3XDataRight(TimeSeries mSeries,TimeSeries plmSeries,TimeSeries lmSeries) {
		gt3xPlotRight.setDataset(0, new TimeSeriesCollection(mSeries));
		gt3xPlotRight.setDataset(1, new TimeSeriesCollection(plmSeries));
		gt3xPlotRight.setDataset(2, new TimeSeriesCollection(lmSeries));
		gt3xPlotRight.setRenderer(0, mRenderer);
		gt3xPlotRight.setRenderer(1, plmRenderer);
		gt3xPlotRight.setRangeAxis(0, new NumberAxis("GT3X Movement Intensity"));
		gt3xPlotRight.setRangeAxis(1, new NumberAxis("is PL-Movement"));
		gt3xPlotRight.mapDatasetToRangeAxis(0, 0);
		gt3xPlotRight.mapDatasetToRangeAxis(1, 1);
		gt3xPlotRight.setForegroundAlpha(0.6f);
	}
	public void setPSGData(TimeSeries mSeries,TimeSeries plmSeries,TimeSeries lmSeries) {
		psgPlot.setDataset(0, new TimeSeriesCollection(mSeries));
		psgPlot.setDataset(1, new TimeSeriesCollection(plmSeries));
		psgPlot.setDataset(2, new TimeSeriesCollection(lmSeries));
		psgPlot.setRenderer(0, mRenderer);
		psgPlot.setRenderer(1, plmRenderer);
		psgPlot.setRangeAxis(0, new NumberAxis("PSG Movement Intensity"));
		psgPlot.setRangeAxis(1, new NumberAxis("is PL-Movement"));
		psgPlot.mapDatasetToRangeAxis(0, 0);
		psgPlot.mapDatasetToRangeAxis(1, 1);
		psgPlot.setForegroundAlpha(0.6f);
	}
	
	public XYPlot getGT3XPlot(){
		return gt3xPlotLeft;
	}
	public XYPlot getPSGPlot(){
		return psgPlot;
	}

	public void setLmRenderer(XYItemRenderer lmRenderer) {
		this.mRenderer =  lmRenderer;
	}

	public XYItemRenderer getLmRenderer() {
		return mRenderer;
	}

	public void setPlmRenderer(XYItemRenderer plmRenderer) {
		this.plmRenderer =  plmRenderer;
	}

	public XYItemRenderer getPlmRenderer() {
		return plmRenderer;
	}
	

}
